/**
 * Created by Administrator on 2017/3/7 0007.
 */
var Page1= {
    create: function () {
        var page = {};

        var tw_bga,tw_bgb,tw_whole;

        page.ui=new PIXI.DisplayObjectContainer();
        var bgA=new PIXI.Sprite(resource['assets/images/page1_bga.png'].texture);
        bgA.y=-80;
        bgA.alpha=1;
        page.ui.addChild(bgA);


        var bgB=new PIXI.Sprite(resource['assets/images/page1_bgb.png'].texture);
        bgB.alpha=0;
        bgB.y=-80;
        page.ui.addChild(bgB);


        var arrow=new PIXI.Sprite(resource['assets/images/arrow.png'].texture);
        arrow.alpha=0;
        arrow.anchor.set(0.5);
        arrow.x=1136-70;
        arrow.y=740/2;
        page.ui.addChild(arrow);
        new TWEEN.Tween({alpha:1,x:1136-70})
            .to({alpha:0.7,x:1136-85},700)
            .onUpdate(function () {
                arrow.alpha=this.alpha;
                arrow.x=this.x;
            })
            .yoyo(true)
            .repeat(Infinity)
            .easing(TWEEN.Easing.Cubic.InOut)
            .start();


        page.In=function () {
            if(tw_bga)
            {
                tw_bga.stop();
                TWEEN.remove(tw_bga);
            }
            if(tw_bgb)
            {
                tw_bgb.stop();
                TWEEN.remove(tw_bgb);
            }

            bgA.alpha=1;
            bgB.alpha=0;
            page.ui.addChild(bgB);
            page.ui.addChild(arrow);

            tw_bga=new TWEEN.Tween({alpha:0})
                .to({alpha:1},4000)
                .onUpdate(function () {
                    bgA.alpha=this.alpha;
                })
                .onComplete(function () {
                    tw_bgb.start();
                    this.alpha=0;
                    bgB.alpha=0;
                    page.ui.addChild(bgB);

                });

            tw_bgb=new TWEEN.Tween({alpha:0})
                .to({alpha:1},4000)
                .onUpdate(function () {
                    bgB.alpha=this.alpha;
                })
                .onComplete(function () {
                    // tw_bga.start();
                    this.alpha=0;
                    bgA.alpha=0;
                    page.ui.addChild(bgA);

                }).start();


            tw_bgb.start();
        };
        page.Out=function () {
            tw_bga.stop();
            tw_bgb.stop();
            tw_whole=new TWEEN.Tween({alpha:1})
                .to({alpha:0},200)
                .onUpdate(function () {
                    // page.ui.alpha=this.alpha;
                })
                .onComplete(function () {
                    bgA.alpha=1;
                    bgB.alpha=0;
                })
                .easing(TWEEN.Easing.Cubic.InOut)
                .start();
        }


        return page;
    }
}